Library Rules
Overviewβ
There are common situations where a business rule or expression can be used in different scenarios across the same project to perform a specific capability.
To avoid rewriting the same rule or expression in each of those scenarios, Bizagi features Library Rules.
Library Rules (also known as Global Rules) can be reused across all applications and processes within the same project.
This way, users developing processes will only write the rule once and associate it wherever needed.
Applicability and Conceptsβ
Some examples of Library Rules include:
- Obtaining today's date
- Retrieving the case creator's ID
- Validating if a given date is a holiday
Library rules work just like business rules, but they do not have a context since they can be invoked from anywhere in the project.
π This means that Library Rules do not have access to the Data Model, so XPaths cannot be used.
Keeping Library Rules Organizedβ
In some projects, many Library Rules may be needed, making it difficult to find specific rules and keep them updated.
To maintain organization, it is recommended to use Expression Families, which let you group related rules.
Creating an Expression Familyβ
Before creating a Library Rule, first create an Expression Family:
- Go to Expert View.
- Navigate to Business Rules β Library Rules.
- Click New Expression Family.
- A window appears prompting for a name. Enter the desired name and click OK.
- The new Expression Family will appear in the main panel.
For example, if you name the family "Date", the result will be:
Each Expression Family can contain multiple rules.
Creating Library Rulesβ
Library Rules can be created independently or as part of an Expression Family.
To create a standalone rule:β
- Click New Library Rule (next to the "New Expression Family" option).
To create a rule inside a family:β
- Right-click on an existing Expression Family.
- Select New Library Rule from the menu.
Either way, a similar window appears:
Configuring the Rule:β
- Display Name & Name: Set a unique identifier for the rule.
- Description: Provide details about the rule's purpose.
- Expression Family: (Optional) Select an existing family for the rule.
- Return Type & Parameters: Define what the rule will return and what inputs it needs.
- Rule Logic: Build the rule using the expression editor.
π Note:
Since Library Rules do not have a context, they cannot access the Data Model.
Avoid using XPath functions or references like Me.getXPath
, Me.newCollectionItem
, or <count(XPath)>
.
Using Library Rulesβ
After setting up a Library Rule, you can use it within any process.
- Open the Expression Editor.
- Click on Library Rules.
- A tree view appears, showing all Library Rules in the project, organized by Expression Family.
- Select the desired rule and click OK.
A pop-up window appears, asking where to store the returned value.
There are two ways to store the output:β
- Variable Storage (Pencil Icon)
- Choose an existing variable or create a new one.
- The ruleβs result is stored for later use.
- Attribute Storage (Diagram Icon)
- Select an attribute from the Data Model to store the result.
- The ruleβs result is immediately assigned to an entity attribute.
π The third button clears any previous configurations.
In both cases, the rule invocation is formatted as an assignment statement, similar to programming languages:
- Left Side: The variable or attribute storing the result.
- Right Side: The Library Rule invocation with any input parameters inside parentheses.
Example:
vDate = LibraryRule(Todayβs Date)
Examples
Rely on the following two examples for additional guidance.
Example 1 - Today's date
Suppose you work in a bank and that whenever an applicant of a loan makes a request, you want to set the receive date.
This way you make sure that whenever a new case is created, the Request date is defaulted to "today".
Now in another process, Purchase Request, suppose you need to set an minimum valid date for the delivery: It has to be later than today, because a delivery date can only be from the next day onwards.
Since there are different scenarios that need to have a date be checked and compared to the current date (today), it makes sense to create a single business rule and reuse it throughout all points of processes needing such validation.
Note that this rule doesn't need any context.
There is no data model manipulation, it is a matter of just sending today's date and receiving concluding information.
To resolve the above, we create a Global rule that returns Today's Date using the function on the Duration-Date category.
In the Expert view go to Business Rules. Right-click Expressions under the Business Rules classification and select New Scripting Expression.
If you have Families of rules created you can allocate this rule to a family in the Rule Family drop-down list, or leave it blank.
We can use this rule in the Forms Modeler for any Process, to set a Default value, or a minimum/maximum date.
Open the Forms Modeler, select the attribute where you wish to relate the rule.
Select default value and choose the rule. Make sure that this rule returns a value.
Notice that this example returns the value contained in vDate.